package util;

import org.w3c.dom.events.Event;
import org.w3c.dom.events.EventListener;

import svg.BoardAdapter;
import svg.GameController;

/**
 * Base class to handle all kind of events on UI object in the game.
 */
public abstract class ObjectListener implements EventListener
{
	protected GameController _controller;
	protected BoardAdapter _boardAdapter;
	protected SoundManager _soundManager;

	public ObjectListener(GameController controller, BoardAdapter boardAdapter)
	{
		_controller = controller;
		_boardAdapter = boardAdapter;
		_soundManager = controller.getSoundManager();
	}

	@Override
	public void handleEvent(Event evt)
	{
		if (_controller == null)
		{
			throw new IllegalArgumentException("GameController must not be null");
		}
		if (_boardAdapter == null)
		{
			throw new IllegalArgumentException("BoardAdapter must not be null");
		}
		fire(evt);
	}

	/**
	 * This method will be executed if an event was fired.
	 * 
	 * @param evt the fired event
	 */
	protected abstract void fire(Event evt);
}
